<!--
- Author:  LiShibin.
- Date:    2018/8/30.
- File:    transactionSeller.
-->
<template>
  <div>
    <div class="Withdrawals">
      <ul>
        <li class="f-cb">
          <!--<i class="iconfont icon-downdot"></i>-->
          <label><span class="nim">售出</span><span>云宝</span>
          <!--<select v-model="style"><option value="1">云宝</option>-->
          <!--&lt;!&ndash;<option value="2">花股</option><option value="3">花粉</option>&ndash;&gt;-->
        <!--</select>-->
        </label></li>
        <li><label><span class="nim">数量</span><input type="number" placeholder="请输入卖出数量" v-model="balance_num"></label></li>
        <li><label><span class="nim">单价</span><input type="number" placeholder="请输入单价" v-model="balance_price"></label></li>
        <li><label><span class="nim">联系电话</span>{{mobile}}</label></li>
        <li class="f-cb"><i class="iconfont icon-downdot"></i><label><span class="nim">出售</span>
          <select v-model="pay_style">
            <!--<option value="1">支付宝</option>-->
            <!--<option value="2">微信</option>-->
            <option value="3">银行卡</option>
          </select></label></li>
      </ul>

    </div>
    <div class="Withdrawals mt10">
      <ul>
        <!--<li v-show="pay_style==1"><label><span class="nim">支付宝账号</span><input type="text" placeholder="请输入支付宝账号" v-model="alipayAccount"></label></li>-->
        <!--<li v-show="pay_style==2"><label><span class="nim">微信账号</span><input type="text" placeholder="请输入微信账号" v-model="wxAccount"></label></li>-->
        <li><label><span class="nim">开户名</span>{{trueName}}</label></li>
        <li><label><span class="nim">银行</span>{{bank_name}}</label></li>
        <li><label><span class="nim">开户行</span>{{bank}}</label></li>
        <li><label><span class="nim">卡号</span>{{bank_id}}</label><a class="newselect" @click="reChoose">重新选择</a></li>
      </ul>
    </div>
    <div class=" p20">
      <button type="button" class="but_1 wauto" @click="addTransaction" v-show="sign == 0">确认挂单</button>
      <button type="button" class="but_1 wauto" @click="addTransaction" v-show="sign != 0">确认挂单</button>
    </div>
    <p style="margin-left: 20px;color: #cc0000;font-size: 16px">*销售的单价最高为0.95</p>
    <back-nav></back-nav>
    <footer-tab></footer-tab>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'

  export default {
    mixins: [
      mapModules({memberInfo: 'memberInfo'}),
      mapRules({need: ['memberInfo']})
    ],
    data() {
      return {
        pay_style: 3,
        balance_num: '',
        balance_price: '0.95',
        mobile: '',
        style: 1,
        pay_info: '',
        alipayAccount: '',
        wxAccount: '',
        trueName: '',
        bank: '',
        bank_id: '',
        sign: 0,
        bank_name: ''
      }
    },
    created() {
      this.trueName = this.memberInfo.bank_member_name
      this.bank = this.memberInfo.bank_deposit
      this.bank_id = this.memberInfo.bank_accoount
      this.bank_name = this.memberInfo.bank_name
      this.mobile = this.memberInfo.member_mobile
    },
    watch: {
      balance_price: function () {
        if (parseFloat(this.balance_price) > 0.95) {
          this.balance_price = '0.95'
          this.$toast('销售单价最高为0.95')
        }
      }
    },
    components: {},
    methods: {
      reChoose() {
        this.$router.push({name: 'setting-bankCard'})
      },
      addTransaction() {
        let num = this.balance_num % 100
        if (num != 0) {
          this.$toast('销售金额只能为100的整数')
          return
        }
        if (this.balance_num == 0) {
          this.$toast('请输入币种的数量')
          return
        }
        if (this.balance_price == 0) {
          this.$toast('请输入价格')
          return
        }
        if (!this.$validator.phone(this.mobile)) {
          this.$toast('请输入电话号码')
          return
        }
        let params = {
          balance_num: this.balance_num,
          balance_price: this.balance_price,
          mobile: this.mobile,
          pay_style: this.pay_style,
          style: this.style,
          pay_info: []
        }
        if (this.style == 1) {
          console.log(this.balance_num)
          if (parseFloat(this.memberInfo.freeze_balance) < this.balance_num) {
            this.$toast('您输入的数量超出拥有')
            return
          }
        } else if (this.style == 2) {
          if (parseFloat(this.memberInfo.hg_balance) < this.balance_num) {
            this.$toast('您输入的数量超出拥有2')
            return
          }
        } else if (this.style == 3) {
          if (parseFloat(this.memberInfo.hf_balance < this.balance_num)) {
            this.$toast('您输入的数量超出拥有3')
            return
          }
        }
        if (this.pay_style == 1) {
          if (this.alipayAccount == '') {
            this.$toast('请输入支付宝账号')
            return
          }
          params.pay_info.account = this.alipayAccount
        } else if (this.pay_style == 2) {
          if (this.wxAccount == '') {
            this.$toast('请输入微信账号')
            return
          }
          params.pay_info.account = this.wxAccount
        } else if (this.pay_style == 3) {
          if (this.trueName == '') {
            this.$toast('请输入真实姓名')
            return
          }
          if (this.bank_id == '') {
            this.$toast('请输入银行卡号')
            return
          }
          if (this.bank_name == '') {
            this.$toast('请输入银行')
            return
          }
          if (this.bank == '') {
            this.$toast('请输入开户行')
            return
          }
          params.pay_info.account = this.trueName
          params.pay_info.bank = this.bank
          params.pay_info.bank_id = this.bank_id
          params.pay_info.bank_name = this.bank_name
        }
        this.sign = 1
        this.$request.addTransaction(params).then(data => {
          this.sign = 0
          this.$toast('上架成功')
          this.$router.push({name: 'transfer-transaction'})
        }).catch(e => {
          this.sign = 0
          this.$toast('上架失败：' + e.msg)
        })
      }
    }
  }
</script>

<style>

</style>
